import React from 'react';
import PropTypes from 'prop-types';
import { Balloon, Button, PopConfirm } from '@teamix/ui';
import intl from '../../../../../../../../../../locale';

export default class DeleteModal extends React.Component {
  static propTypes = {
    record: PropTypes.object,
  };

  static defaultProps = {
    record: {},
  };

  constructor(props) {
    super(props);
    this.state = {
      visible: false,
    };
  }

  onClose = () => {
    this.setState({
      visible: false,
    });
  };

  render() {
    const { record, isOrgOwner, auto_sync_member_enable } = this.props;
    if (!isOrgOwner) {
      return (
        <Balloon.Tooltip
          trigger={
            <Button type="normal" className="setting-table-handle-item-for-hack" text disabled>
              {intl.get({
                id: 'code-assets.containers.deleteAdminPopConfirm.Remove',
                defaultMessage: '移除',
              })}
            </Button>
          }
          align="t"
        >
          {intl.get({
            id: 'code-assets.containers.deleteAdminPopConfirm.YouAreNotAuthorizedTo',
            defaultMessage: '无操作权限，请联系企业拥有者处理',
          })}
        </Balloon.Tooltip>
      );
    }

    if (record.access_level === 70) {
      return (
        <Balloon.Tooltip
          trigger={
            <Button type="normal" className="setting-table-handle-item-for-hack" text disabled>
              {intl.get({
                id: 'code-assets.containers.deleteAdminPopConfirm.Remove',
                defaultMessage: '移除',
              })}
            </Button>
          }
          align="t"
        >
          {intl.get({
            id: 'code-assets.containers.deleteAdminPopConfirm.TheOwnerCannotBeRemoved',
            defaultMessage: '无法移除拥有者',
          })}
        </Balloon.Tooltip>
      );
    }

    if (record.sync_from_org && auto_sync_member_enable) {
      return (
        <Balloon.Tooltip
          trigger={
            <Button type="normal" className="setting-table-handle-item-for-hack" text disabled>
              {intl.get({
                id: 'code-assets.containers.deleteAdminPopConfirm.Remove',
                defaultMessage: '移除',
              })}
            </Button>
          }
          align="t"
        >
          {intl.get({
            id: 'code-assets.containers.deleteAdminPopConfirm.TheCurrentUserIsSynchronized',
            defaultMessage:
              '当前用户同步自云效企业管理员， 暂不支持移除，请先关闭「同步云效企业管理员」开关后再试。',
          })}
        </Balloon.Tooltip>
      );
    }

    return (
      <PopConfirm
        type="danger"
        triggerType="click"
        align="l"
        title="移除管理员"
        content={intl.get({
          id: 'code-assets.containers.deleteAdminPopConfirm.AreYouSureYouWant',
          defaultMessage: '您确定要移除该管理员吗？',
        })}
        trigger={
          <Button type="primary" text className="setting-table-handle-item-for-hack">
            {intl.get({
              id: 'code-assets.containers.deleteAdminPopConfirm.Remove',
              defaultMessage: '移除',
            })}
          </Button>
        }
        onConfirm={() => {
          this.props.remove(record.id);
          this.onClose();
        }}
        onCancel={this.onClose}
        visible={this.state.visible}
        onVisibleChange={(visible) => {
          this.setState({
            visible,
          });
        }}
      />
    );
  }
}
